﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

static class ExpManager
{
    public static int CalcExp(unit victim)
    {
       // XP = (Base XP) *(1 +  (Mob Level - Char Level)/zd )
        int baseXP = (Player.MyInstance.MyLevel * 5) + 45;
        int grayLvl = CalculateGrayLvl();
        int totalEXP = 0;
        if (victim.MyLevel > Player.MyInstance.MyLevel)
        {
            totalEXP = (int)(baseXP * (1 + 0.05 * (victim.MyLevel - Player.MyInstance.MyLevel)));
        }
        else if (victim.MyLevel > grayLvl)
        {
            totalEXP = baseXP * (1 - (Player.MyInstance.MyLevel - victim.MyLevel) / ZeroDiff()); 
        }
        
        
        return totalEXP;
    }
    private static int ZeroDiff()
    {
        if (Player.MyInstance.MyLevel <= 7)
        {
            return 5;
        }
        else if (Player.MyInstance.MyLevel <= 9)
        {
            return 6;
        }
        else if (Player.MyInstance.MyLevel <= 11)
        {
            return 7;
        }
        else if (Player.MyInstance.MyLevel <= 15)
        {
            return 8;
        }
        else if (Player.MyInstance.MyLevel <= 19)
        {
            return 9;
        }
        else if (Player.MyInstance.MyLevel <= 29)
        {
            return 11;
        }
        else if (Player.MyInstance.MyLevel <= 39)
        {
            return 12;
        }
        else if (Player.MyInstance.MyLevel <= 44)
        {
            return 13;
        }
        else if (Player.MyInstance.MyLevel <= 49)
        {
            return 14;
        }
        else if (Player.MyInstance.MyLevel <= 54)
        {
            return 15;
        }
        else if (Player.MyInstance.MyLevel <= 59)
        {
            return 16;
        }
        else if (Player.MyInstance.MyLevel <= 79)
        {
            return 17;
        }
        else if (Player.MyInstance.MyLevel <= 99)
        {
            return 18;
        }
        
        return 19;
        
    }
    private static int CalculateGrayLvl()
    {
        if (Player.MyInstance.MyLevel <= 5)
        {
            return 0;
        }
        else if (Player.MyInstance.MyLevel <= 49)
        {
            return Player.MyInstance.MyLevel - Player.MyInstance.MyLevel / 10 - 5;
        }
        else if(Player.MyInstance.MyLevel == 50)
        {
            return 40;
        }
        else if (Player.MyInstance.MyLevel < 59)
        {
            return Player.MyInstance.MyLevel - Player.MyInstance.MyLevel / 5 - 1;
        }
        else
        {
            return Player.MyInstance.MyLevel - 9;
        }
    }
}

